<template>
	<view>
		<Navbar :isReturn="false"></Navbar>
		<Info :userData="userData" @toRecharge="toRecharge" @onShare="onShare"></Info>
		<PassWay :userData="userData" @updateShopName="updateShopName" :shop_name="userData.mall.shop_name" :list="passList" :useList="useList" :serviceList="serviceList" :goodsList="goodsList" @goModule="goModule" @goUse="goUse"
			@goCenter="goCenter">
		</PassWay>
		<view class="u-flex u-row-center u-m-t-56">
			<view @click="handleOpenAdviser" class="mine_phone u-flex u-back-white">
				<u-icon size="42" color="#464855FF" name="a-icon-customerservice" custom-prefix="custom-icon" />
				<text class="u-font-24 u-p-l-20">专属顾问</text>
			</view>
		</view>
		<view class="u-text-center u-color-gray u-m-t-40">技术支持：橙美科技</view>
		<view style="height: 40rpx;"></view>
		<Tabbar></Tabbar>

		<u-popup mode="center" length="80%" border-radius="20" :closeable="true" :mask-close-able="false"
			v-model="settleShow">
			<view class="u-p-t-30 u-p-b-30 u-p-l-20 u-p-r-20">
				<view class="u-text-center u-font-30 u-font-bold u-m-t-20 u-m-b-30">公司入驻</view>
				<view class="u-font-26">请准备好以下两份资料后再点击签订协议认证。</view>
				<view class="u-font-26 u-m-t-20 u-text-line-15">1.下载入驻协议，打印后签字加盖企业公章，扫描成图片jpg/png格式</view>
				<view class="u-font-26 u-m-t-20">2.公司营业执照</view>
				<view class="u-m-t-30 u-flex u-row-center">
					<view class="settle_down" @click="downLoadFile">下载入驻协议</view>
				</view>
				<view class="u-m-t-30 u-flex u-row-center">
					<view class="settle_btn" @click="goCompanyForm">签订协议去认证</view>
				</view>
			</view>
		</u-popup>

		<Modal :show="modal.show" :confirmText="modal.confirm" :cancelText="modal.cancel" :modalContent="modal.content"
			:showCancel="modal.showCancel" :showConfirm="modal.showConfirm" @confirm="modalConfirm"
			@cancel="modal.show = false"></Modal>

		<!-- 客服联系 -->
		<u-popup v-model="adviserShow" mode="bottom" border-radius="20">
			<view class="u-p-30">
				<view class="u-m-t-40 u-m-b-40">
					<button open-type="contact" class="shareBtn">在线客服</button>
				</view>
				<view class="u-m-t-40 u-m-b-40">
					<button class="shareBtn" @click="handleCall">电话联系</button>
				</view>
			</view>
		</u-popup>

		<!-- 引导加入青创私董训练营 -->
		<u-popup v-model="joinCode.show" mode="center" border-radius="20" :mask-close-able="false" :closeable="true"
			close-icon-size="40" width="90%" @close="joinCode.show = false">
			<view class="u-p-20 u-p-t-60">
				<view class="u-m-t-20 u-m-b-20 u-font-bold u-font-32 u-text-center">请进入该群预约青创私董训练营课程</view>
				<u-image class="u-m-t-20 u-width-100" :src="joinCode.image" mode="widthFix"></u-image>
			</view>
		</u-popup>

		<!-- 捐赠二维码 -->
		<DonatePopup :popupShow="donateData.show" :url="donateData.url" @popupClose="donateData.show = false">
		</DonatePopup>
		
		<!-- 分享名片 -->
		<PosterImage :data="posterData" @closePosterImage="posterData.show = false"></PosterImage>
	</view>
</template>

<script>
	import Navbar from '@/components/Navbar.vue'
	import Tabbar from '@/components/Tabbar.vue'
	import Info from './component/Info.vue'
	import PassWay from './component/PassWay.vue'
	import Modal from '@/components/Modal.vue'
	import PosterImage from '@/components/PosterImage.vue'
	import DonatePopup from '@/components/DonatePopup.vue'
	import {
		userInfo,
		cardNumber,
		getShare,
		getConfigInfo,
		userCompanyQrcode,
	} from '@/network/api.js'
	import {
		teaJoinNum,
		teaGoodsList,
		teaDrawStatus
	} from '@/network/tea.js'
	import {
		PresidentLevel,
    TeaStatus,
		presidentClass,
		call,
		pointTransform
	} from '@/utils/index.js'
	export default {
		components: {
			Navbar,
			Tabbar,
			Info,
			PassWay,
			Modal,
			PosterImage,
			DonatePopup
		},
		data() {
			return {
				passList: [{
						name: '酒局',
						color: '#FF5548',
						src: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20250723671283139878.png',
						path: '/pages/myBureau/myBureau'
					},
					{
						name: '活动',
						color: '#369BFF',
						src: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20250723887017345968.png',
						path: '/pages/myActivity/myActivity'
					},
					{
						icon: 'qiuzhu',
						name: '订单',
						src: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20250723588841202414.png',
						path: '/teaBureau/teaOrderList/teaOrderList'
					},
					{
						name: '评价',
						color: '#FF9343',
						src: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20250723212840655855.png',
						path: '/pages/myPoint/myPoint'
					},
					{
						name: '名片',
						color: '#43D143',
						src: 'https://lrcj.oss-cn-shenzhen.aliyuncs.com/images/common/20250723362456677631.png',
						// path: '/operate/exhibitionRecord/exhibitionRecord'
						path: `/teaBureau/teaPersonDetail/teaPersonDetail?id=${uni.getStorageSync("user_id")}`
					}
				],
				useList: [
					{
						id: 1,
						icon: 'icon-user',
						name: '好友管理',
						desc: '',
						count: 0
					}, /* {
						id: 12,
						icon: 'icon-couponyouhuiquan',
						name: '邀请注册'
					},{
						id: 2,
						icon: 'icon-top',
						name: '宣传推广',
					}, */
					{
						id: 3,
						icon: 'icon-message',
						name: '消息中心',
						desc: '',
						count: 0
					},
					/* {
						id: 4,
						icon: 'icon-list',
						name: '订单管理',
					}, */
					{
						id: 5,
						icon: 'icon-couponyouhuiquan',
						name: '订单发票'
					}/* ,
					{
						id: 6,
						icon: 'icon-list',
						name: '创微基金捐赠'
					} */
				],
				serviceList: [{
						id: 7,
						icon: 'icon-help',
						name: '帮助中心',
					},
					/* {
						id: 8,
						icon: 'icon-message1',
						name: '联系合作'
					}, */
					/* {
						id: 8,
						icon: 'icon-help',
						name: '请我喝茶'
					}, */
					{
						id: 10,
						icon: 'icon-set',
						name: '设置中心',
					},
					{
						id: 11,
						icon: 'icon-conmentpinglun',
						name: '意见反馈',
					}
				],
				user_id: uni.getStorageSync("user_id"),
				userData: {},
				modal: {
					show: false,
					showCancel: true,
					showConfirm: true,
					confirm: '确定',
					cancel: '取消',
					content: ''
				},
				adviserShow: false,
				adviserPhone: '',
				joinCode: {
					show: false,
					image: ''
				},
				donateData: {
					show: false,
					url: ''
				},
				posterData: {
					show: false,
					image: '',
					next: 0
				},
				goodsList: []
			}
		},
		onLoad() {
			this.handleGetGoodsList()
			this.handleGetConfigPhone()
		},
		onShow() {
      
			this.handleGetUserInfo()
			this.handleGetCardNumber()
		},
		methods: {
      updateShopName(shop_name){
        console.log('shop_name', shop_name);
        this.handleGetUserInfo()
      },
			async handleGetConfigPhone() {
				const res = await getConfigInfo({
					key: 'phone'
				})
				this.adviserPhone = res.data.value
			},
			async handleGetGoodsList(){
				const params = {
					page: 1,
					limit: 10,
					type: -1,
					position: 2
				}
				const res = await teaGoodsList(params)
				this.goodsList = res.data.list
			},
			handleCallOrder() {
				call(this.orderData.mobile)
			},
			handleGetUserInfo() {
				userInfo({
					user_id: this.user_id
				}).then(res => {
					res.data.president_status = parseInt(res.data.president_status)
					res.data.partner_status = parseInt(res.data.partner_status)
					res.data.integral = pointTransform(res.data.integral)
					res.data.money = pointTransform(res.data.money)
					res.data.number = pointTransform(res.data.number)
					res.data.holder.inviter_num = pointTransform(res.data.holder.inviter_num)
					if ([5, 6, 7, 8].includes(res.data.president_status)) {
						res.data.president_name = this.getPresidentName(res.data.partner_status,res.data.president_status)
						res.data.president_class = presidentClass(res.data.president_status)
					} else {
						res.data.president_name = ''
					}
					uni.setStorageSync("user_name", res.data.name)
					uni.setStorageSync("user_phone", res.data.phone)
					uni.setStorageSync("user_isBlack", res.data.is_black)
					this.userData = res.data
					this.useList.map(item => {
						if (item.id == 3) {
							item.count = res.data.message_number
							item.desc = res.data.message_number > 0 ? `${res.data.message_number}个未读消息` :
								''
						}
					})
				})
			},
			handleGetCardNumber() {
				cardNumber({
					userid: this.user_id
				}).then(res => {
					this.useList.map(item => {
						if (item.id == 1) {
							item.count = res.data.number
							item.desc = res.data.number > 0 ? `${res.data.number}个待审核申请` : ''
						}
					})
				})
			},
			toRecharge(val) {
				switch(val){
					case 1:
					    /* uni.navigateTo({
					    	url: "/pages/scoreList/scoreList"
					    }) */
						uni.navigateTo({
							url: "/pages/scoreGoodsShop/scoreGoodsShop"
						})
						break;
					case 2:
					    uni.navigateTo({
					    	url: "/operate/recordList/recordList"
					    })
					    break;
					case 3:
					    uni.navigateTo({
					    	url: "/operate/energyList/energyList"
					    })
						break;
					case 4:
					    uni.navigateTo({
					    	url: "/pages/invitationList/invitationList"
					    })
						break;
				}
			},
			goModule(val) {
				uni.navigateTo({
					url: `${val.path}`
				})
			},
			async goUse(val) {
				this.modal.showConfirm = true
				this.modal.cancel = '取消'
				switch (val.id) {
					case 1:
						uni.navigateTo({
							url: "/pages/friendCenter/friendCenter"
						})
						break;
					case 2:
						uni.navigateTo({
							url: "/operate/advertList/advertList"
						})
						break;
					case 3:
						uni.navigateTo({
							url: "/pages/messageList/messageList"
						})
						break;
					case 4:
						uni.showToast({
							title: "暂未开放",
							icon: "none"
						})
						break;
					case 5:
						uni.navigateTo({
							url: "/pages/orderList/orderList"
						})
						break;
					case 6:
						const res = await getConfigInfo({
							key: 'donate'
						})
						this.donateData.url = res.data.value
						this.donateData.show = true
						break;
					case 7:
						uni.navigateTo({
							url: "/pages/helpCenter/helpCenter"
						})
						break;
					case 8:
						uni.navigateTo({
							url: "/operate/feedback/feedback?type=1"
						})
						break;
					case 9:
						uni.showToast({
							title: "暂未开放",
							icon: "none"
						})
						break;
					case 10:
						uni.navigateTo({
							url: "/pages/setupCenter/setupCenter"
						})
						break;
					case 11:
						uni.navigateTo({
							url: "/operate/feedback/feedback?type=2"
						})
						break;
					case 12:
					    uni.navigateTo({
					    	url: "/pages/invitationList/invitationList"
					    })
						break;
				}
			},
			modalConfirm() {
				this.modal.show = false
			},
			handleOpenAdviser() {
				this.adviserShow = true
			},
			handleCall() {
				this.adviserShow = false
				uni.makePhoneCall({
					phoneNumber: this.adviserPhone
				})
			},
			async goCenter(val) {
				if (uni.getStorageSync("user_isBlack") == 0) {
					switch(val){
						// 青创私董
						case 1:
						    switch (this.userData.president_status) {
						    	case 0:
						    	case 2:
						    	case 4:
								    const pre = await teaDrawStatus({type:'president',user_id: this.user_id})
									if(pre.data.is_have == 1 && pre.data.is_have_two == 0){
										uni.setStorageSync("bank",pre.data)
										uni.navigateTo({
											url: "/teaBureau/teaBankOrder/teaBankOrder"
										})
									}
									if(pre.data.is_have_two == 1){
										uni.showToast({
											title: "您正在申请成为青创分汇，请先完成付款流程",
											icon: "none",
											duration: 3000
										})
									}
									if(pre.data.is_have == 0 && pre.data.is_have_two == 0){
										uni.navigateTo({
											url: "/teaBureau/teaAgreement/teaAgreement"
										})
									}
						    		break;
						    	case 1:
						    	    const res= await getConfigInfo({key: 'join_code'})
						    		this.joinCode.image = res.data.value
						    		this.joinCode.show = true
						    		break;
						    	case 3:
						    		return
						    		break;
						    	default:
						    		uni.navigateTo({
						    			url: "/teaBureau/teaPresidentCenter/teaPresidentCenter"
						    		})
						    		break;
						    }
							break;
						// 合同人
						case 2:
						    if (this.userData.partner_status >= 5) {
						        uni.navigateTo({
						        	url: "/teaBureau/teaPartnerCenter/teaPartnerCenter"
						        })
						    } else {
								const par = await teaDrawStatus({type:'partner',user_id: this.user_id})
								if(par.data.is_have == 1 && par.data.is_have_two == 0){
									uni.setStorageSync("bank",par.data)
									uni.navigateTo({
										url: "/teaBureau/teaBankOrder/teaBankOrder"
									})
								}
								if(par.data.is_have_two == 1){
									uni.showToast({
										title: "您正在申请成为青创私董，请先完成付款流程",
										icon: "none",
										duration: 3000
									})
								}
								if(par.data.is_have == 0 && par.data.is_have_two == 0){
									uni.navigateTo({
										url: "/teaBureau/teaPartnerAgreement/teaPartnerAgreement"
									})
								}
						    }
							break;
						// 青创分汇
						case 3:
			                switch(this.userData.holder.center_apply_status){
								case 0:
								    uni.navigateTo({
								    	url: "/teaBureau/teaCenterForm/teaCenterForm"
								    })
									break;
								case 1:
								    this.modal.content = '审核中，请耐心等待'
									this.modal.confirm = '确定'
									this.modal.show = true
									break;
								case 2:
								    uni.navigateTo({
								    	url: "/teaBureau/teaCenter/teaCenter"
								    })
									break;
							}
							break;
					}
				} else {
					this.modal.content = '当前用户权限受限，请联系系统管理员'
					this.modal.confirmText = '确定'
					this.modal.show = true
				}
			},
			getPresidentName(status1, status2) {
				// return PresidentLevel(status)
        return TeaStatus(status1, status2)  
			},
			onShare(){
				uni.showLoading({
					title:"加载中"
				})
				const params = {
					user_id: uni.getStorageSync("user_id"),
				}
				userCompanyQrcode(params).then(res => {
					this.posterData.image = res.data.url
					this.posterData.show = true
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.settle_down {
		background: #ecf5ff;
		border: 1rpx solid #a0cfff;
		color: #2C76ED;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.settle_btn {
		background: #2C76ED;
		color: #fff;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.mine_phone {
		padding: 16rpx 35rpx;
		border: 1rpx solid #eee;
		border-radius: 50rpx;
	}

	.adviser_btn {
		border-radius: 10rpx;
		padding: 20rpx 30rpx;
		font-size: 30rpx;
		color: #fb6316;
		border: 1rpx solid #fb6316;
		background: #fff;
		display: inline-block;
		line-height: 1
	}

	.shareBtn {
		background: #F5A21A;
		color: #FFF;
	}

	button {
		border-radius: 20rpx !important;
		border: none !important;
		height: 85rpx !important;
		line-height: 85rpx !important;
		font-size: 30rpx !important;
	}

	button::after {
		border: none !important;
	}
</style>